package com.fzz.learnitservice.controller;

import com.commonfzz.pojo.po.R;
import com.fzz.learnitservice.pojo.dto.LoginDTO;
import com.fzz.learnitservice.pojo.dto.RegisterDTO;
import com.fzz.learnitservice.pojo.vo.LoginVo;
import com.fzz.learnitservice.service.IUserService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/access")
@RequiredArgsConstructor
@Validated
public class AccessController {

    private final IUserService iUserService;


    /**
     * 用户端登录
     * @param loginDTO
     * @return
     */
    @PostMapping("/login")
    public R<LoginVo> login(@Valid @RequestBody LoginDTO loginDTO) {
        return iUserService.login(loginDTO);
    }

    /**
     * 用户注册
     * @param registerDTO
     * @return
     */
    @PostMapping("/register")
    public R register(@Valid @RequestBody RegisterDTO registerDTO) {
        return iUserService.register(registerDTO);
    }

    /**
     * 用户端退出
     * @param userId
     * @return
     */
    @GetMapping("/logout")
    public R logout(@RequestParam @NotNull(message = "用户ID不能为空") Long userId) {
        return iUserService.logout(userId);
    }
}
